#include "GLScene.h"

#include <iostream>
#include <sstream>
#include <cmath>
#include <vector>

#include "sdl.h"

#include "GLSceneProjectionMode.h"
#include "GLSceneOrthogonalMode.h"
#include "GLSceneFrameAndMaskDrawers.h"
#include "GLSceneMapDrawers.h"
#include "GLSceneInterfaceDrawers.h"
#include "SiteCoordinate.h"
#include "PathCoordinate.h"

namespace catan
{

const float GLScene::textTop = 0.535f;							//the first line at the Top of the text
const float GLScene::textLeft = 0.015f;							//the top left of the text area
const float GLScene::textHeight = 0.016f;						//main text height
const float GLScene::textWidth = textHeight*32/66;				//this is 1 character width

GLScene::GLScene(GameState &gameState, SDLCanvas &sdlCanvas, GLTextures &glTextures, GameMap &gameMap): gameStateRef(&gameState), sdlCanvasRef(&sdlCanvas), glTexturesRef(&glTextures), gameMapRef(&gameMap), frame(0), turnCounter(0), clickedStartTrade(false)
{
}

GLScene::~GLScene()
{
}

void GLScene::poll()
{
	SDL_Event *mouseButtonDownEvent = gameStateRef->pollMouseButtonDownEvent();
	if (mouseButtonDownEvent != NULL)
	{
		click(mouseButtonDownEvent->button.x, mouseButtonDownEvent->button.y);
	}
	SDL_Event *mouseMotionEvent = gameStateRef->pollMouseMotionEvent();
	if (mouseMotionEvent != NULL)
	{
		int x = mouseMotionEvent->button.x;
		int y = mouseMotionEvent->button.y;
		float xRatio = (sdlCanvasRef->getWindowUnitWidth() - sdlCanvasRef->getClientUnitWidth())/2;
		float yRatio = (sdlCanvasRef->getWindowUnitHeight() - sdlCanvasRef->getClientUnitHeight())/2;
		float clientX = (x - xRatio*sdlCanvasRef->getWidth())*(sdlCanvasRef->getWindowUnitWidth()/sdlCanvasRef->getWidth());
		float clientY = (y - yRatio*sdlCanvasRef->getHeight())*(sdlCanvasRef->getWindowUnitHeight()/sdlCanvasRef->getHeight());
		float calcX = (0.4f-clientX)/(0.09375f*clientY + 0.1335f);
		//float calcY = (9.107f*clientY*clientY - 18.486f*clientY + 3.687f);
		//-3.8008346998012343 + 20.05063303391713x -15.795532422655647x^2 + 8.878439171845189x^3
		float calcY = 8.878439171845189*clientY*clientY*clientY - 15.795532422655647*clientY*clientY + 20.05063303391713*clientY - 3.8008346998012343; 
		float calcX2 = -calcX*2 + 3;
		float calcY2 = calcY + calcX + 3;
		float siteOffsetXs[6] = {0.6667f, 0.3333f, -0.3333f, -0.6667f, -0.3333f, 0.3333f};
		float siteOffsetYs[6] = {-0.3333f, -0.6667f, -0.3333f, 0.3333f, 0.6667f, 0.3333f};
		float pathOffsetXs[6] = {0.5f, 0.0f, -0.5f, -0.5f, 0.0f, 0.5f};
		float pathOffsetYs[6] = {-0.5f, -0.5f, 0.0f, 0.5f, 0.5f, 0.0f};
		mouseMotionArtifacts.clear();
		if (gameStateRef->getIsBuySettlementButtonPressed() || gameStateRef->getIsCityUpgradeButtonPressed())
		{
			for (int j=0; j<6; ++j)
			{
				for (int i=0; i<6; ++i)
				{
					for (int k=0; k<6; k+=3)
					{
						if (calcX2 > (i+siteOffsetXs[k])-0.1f && calcX2 < (i+siteOffsetXs[k])+0.1f &&
						    calcY2 > (j+siteOffsetYs[k])-0.1f && calcY2 < (j+siteOffsetYs[k])+0.1f)
						{
							std::cout << "Site match found at (" << i << ", " << j << ", " << k << "): real: " << calcX2 << ", " << calcY2 << "; goal: " << (i+siteOffsetXs[k]) << ", " << (j+siteOffsetYs[k]) << std::endl;
							CoordinateX coordinateX(static_cast<CoordinateX::Enum_CoordinateX>(i));
							CoordinateY coordinateY(static_cast<CoordinateY::Enum_CoordinateY>(j));
							HorizontalCardinal horizontalCardinal(static_cast<HorizontalCardinal::Enum_HorizontalCardinal>(k*60));
							if (SiteCoordinate::canInit(coordinateX, coordinateY, horizontalCardinal))
							{
								SiteCoordinate siteCoordinate(coordinateX, coordinateY, horizontalCardinal);
								Player* currentPlayer = gameStateRef->getPlayers().at(gameStateRef->getPlayerIndex());
								if (gameStateRef->getIsBuySettlementButtonPressed() && gameStateRef->canAddSettlement(*currentPlayer, *gameMapRef, siteCoordinate))
								{
									mouseMotionArtifacts.setMouseMotionSettlement(SiteCoordinate(coordinateX, coordinateY, horizontalCardinal));
								}
								else if (gameStateRef->getIsBuySettlementButtonPressed() && gameStateRef->canCityUpgrade(*currentPlayer, *gameMapRef, siteCoordinate))
								{
									mouseMotionArtifacts.setMouseMotionCity(SiteCoordinate(coordinateX, coordinateY, horizontalCardinal));
								}
							}
						}
					}
				}
			}
		}
		if (gameStateRef->getIsBuyRoadButtonPressed())
		{
			for (int j=0; j<6; ++j)
			{
				for (int i=0; i<6; ++i)
				{
					for (int k=0; k<6; k+=2)
					{
						if (calcX2 > (i+pathOffsetXs[k])-0.1f && calcX2 < (i+pathOffsetXs[k])+0.1f &&
						    calcY2 > (j+pathOffsetYs[k])-0.1f && calcY2 < (j+pathOffsetYs[k])+0.1f)
						{
							std::cout << "Path match found at (" << i << ", " << j << ", " << k << "): real: " << calcX2 << ", " << calcY2 << "; goal: " << (i+pathOffsetXs[k]) << ", " << (j+pathOffsetYs[k]) << std::endl;
							CoordinateX coordinateX(static_cast<CoordinateX::Enum_CoordinateX>(i));
							CoordinateY coordinateY(static_cast<CoordinateY::Enum_CoordinateY>(j));
							VerticalCardinal verticalCardinal(static_cast<VerticalCardinal::Enum_VerticalCardinal>(k*60+30));
							if (PathCoordinate::canInit(coordinateX, coordinateY, verticalCardinal))
							{
								PathCoordinate pathCoordinate(coordinateX, coordinateY, verticalCardinal);
								Player* currentPlayer = gameStateRef->getPlayers().at(gameStateRef->getPlayerIndex());
								if (gameStateRef->canAddRoad(*currentPlayer, *gameMapRef, pathCoordinate))
								{
									mouseMotionArtifacts.setMouseMotionRoad(pathCoordinate);
								}
							}
						}
					}
				}
			}
		}
	}
}

void GLScene::draw()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	if (gameStateRef->getAreHexagonsDrawn() || gameStateRef->getIsBackgroundDrawn())
	{
		GLSceneProjectionMode::begin(*sdlCanvasRef, -0.2f, 0.0f);
	    	glPushMatrix();
		        glTranslatef(0.0f, 0.15f, 0.0f);
		        glTranslatef(0.0f, 0.0f, -1.0f);
		        //glTranslatef(0.0f, -0.15f, 0.0f);
		        glRotatef(30.0f, 1.0f, 0.0f, 0.0f);
		        glScalef(0.75f, 0.75f, 0.75f);
		        glTranslatef(0.0f, -0.5f, 0.0f);
		    	if (gameStateRef->getAreHexagonsDrawn())
		    	{
		    		GLSceneMapDrawers::drawHexagons(1.0f, *glTexturesRef, *gameMapRef, gameStateRef->getPlayers(), *gameStateRef, mouseMotionArtifacts);
		    	}
		    	if (gameStateRef->getIsBackgroundDrawn())
		    	{
		    		GLSceneMapDrawers::drawBackground(1.5f, glTexturesRef->getSeaTexture());
		    	}
	    	glPopMatrix();
		GLSceneProjectionMode::end();
	}
	if (gameStateRef->getIsMaskDrawn())
	{
	    glClear(GL_DEPTH_BUFFER_BIT);
		GLSceneOrthogonalMode::begin(*sdlCanvasRef);
			GLSceneFrameAndMaskDrawers::drawOrthogonalMaskAroundClient(*sdlCanvasRef);
			GLSceneFrameAndMaskDrawers::drawOrthogonalMaskAroundMapArea(0.0f, 0.2f, 0.3f, 0.0f, *sdlCanvasRef);
		GLSceneOrthogonalMode::end();
	}
    if (gameStateRef->getIsFrameDrawn())
    {
        glClear(GL_DEPTH_BUFFER_BIT);
	    if ((frame%2)==0)
	    {
			GLSceneProjectionMode::begin(*sdlCanvasRef, 0.0f, 0.0f);
				GLSceneFrameAndMaskDrawers::drawProjectionFrameAroundClient(*sdlCanvasRef);
			GLSceneProjectionMode::end();
	    }
	    else
	    {
			GLSceneOrthogonalMode::begin(*sdlCanvasRef);
			GLSceneFrameAndMaskDrawers::drawOrthogonalFrameAroundClient(*sdlCanvasRef);
	    	GLSceneOrthogonalMode::end();
	    }
	    glClear(GL_DEPTH_BUFFER_BIT);
    }
    if (gameStateRef->getIsPreStartGame())
    {
    	glClear(GL_DEPTH_BUFFER_BIT);
		GLSceneOrthogonalMode::begin(*sdlCanvasRef);
			GLSceneInterfaceDrawers::drawRectangularTexture(0.8f, 1.0f, 0.05f, 0.0f, glTexturesRef->getRandomizeTexture(), *sdlCanvasRef);
			GLSceneInterfaceDrawers::drawRectangularTexture(0.8f, 1.0f, 0.10f, 0.05f, glTexturesRef->getStartGameTexture(), *sdlCanvasRef);
		GLSceneOrthogonalMode::end();
    }
    else if(!gameStateRef->isTheEnd())
	{
    	glClear(GL_DEPTH_BUFFER_BIT);
		GLSceneOrthogonalMode::begin(*sdlCanvasRef);
			GLSceneInterfaceDrawers::drawRectangularTexture(0.8f, 1.0f, 0.05f, 0.0f, (gameStateRef->getIsRollDiceButtonEnabled() ? glTexturesRef->getButtonRollDiceTexture() : glTexturesRef->getButtonRollDiceDisabledTexture()), *sdlCanvasRef);
			GLSceneInterfaceDrawers::drawRectangularTexture(0.8f, 1.0f, 0.1f, 0.05f, (gameStateRef->getIsBuyRoadButtonPressed() ? glTexturesRef->getButtonBuyRoadPressedTexture() : (gameStateRef->getIsBuyRoadButtonEnabled() ? glTexturesRef->getButtonBuyRoadTexture() : glTexturesRef->getButtonBuyRoadDisabledTexture())), *sdlCanvasRef);
			GLSceneInterfaceDrawers::drawRectangularTexture(0.8f, 1.0f, 0.15f, 0.1f, (gameStateRef->getIsBuySettlementButtonPressed() ? glTexturesRef->getButtonBuySettlementPressedTexture() : (gameStateRef->getIsBuySettlementButtonEnabled() ? glTexturesRef->getButtonBuySettlementTexture() : glTexturesRef->getButtonBuySettlementDisabledTexture())), *sdlCanvasRef);
			GLSceneInterfaceDrawers::drawRectangularTexture(0.8f, 1.0f, 0.2f, 0.15f, (gameStateRef->getIsCityUpgradeButtonPressed() ? glTexturesRef->getButtonCityUpgradePressedTexture() : (gameStateRef->getIsCityUpgradeButtonEnabled() ? glTexturesRef->getButtonCityUpgradeTexture() : glTexturesRef->getButtonCityUpgradeDisabledTexture())), *sdlCanvasRef);
			GLSceneInterfaceDrawers::drawRectangularTexture(0.8f, 1.0f, 0.25f, 0.2f, (gameStateRef->getIsBuyDevelopmentCardButtonEnabled() ? glTexturesRef->getButtonBuyDevCardTexture() : glTexturesRef->getButtonBuyDevCardDisabledTexture()), *sdlCanvasRef);
			GLSceneInterfaceDrawers::drawRectangularTexture(0.8f, 1.0f, 0.3f, 0.25f, (gameStateRef->getIsPlayerTradeButtonPressed() ? glTexturesRef->getButtonPlayerTradePressedTexture() : (gameStateRef->getIsPlayerTradeButtonEnabled() ? glTexturesRef->getButtonPlayerTradeTexture() : glTexturesRef->getButtonPlayerTradeDisabledTexture())), *sdlCanvasRef);
			GLSceneInterfaceDrawers::drawRectangularTexture(0.8f, 1.0f, 0.35f, 0.3f, (gameStateRef->getIsBankTradeButtonPressed() ? glTexturesRef->getButtonBankTradePressedTexture() : (gameStateRef->getIsBankTradeButtonEnabled() ? glTexturesRef->getButtonBankTradeTexture() : glTexturesRef->getButtonBankTradeDisabledTexture())), *sdlCanvasRef);
			GLSceneInterfaceDrawers::drawRectangularTexture(0.8f, 1.0f, 0.4f, 0.35f, (gameStateRef->getIsEndTurnButtonEnabled() ? glTexturesRef->getButtonEndTurnTexture() : glTexturesRef->getButtonEndTurnDisabledTexture()), *sdlCanvasRef);

		if (!clickedStartTrade){
			std::map<DevelopmentCard, int> privateDevelopments = gameStateRef->getPlayers().at(gameStateRef->getPlayerIndex())->getPrivateDevelopments();
			std::ostringstream outputLeft;
			outputLeft << "Cards in hand\nClick on dev card\nto play it\n";
			int numberOfSoldierCards = privateDevelopments.find(soldierCard)->second;
			if (numberOfSoldierCards == 0) outputLeft << "\n";
			else
			{
				outputLeft << "[   Soldier    ]";
				if (numberOfSoldierCards > 1) outputLeft << " x " << numberOfSoldierCards;
				outputLeft << "\n";
			}
			if (privateDevelopments.find(marketCard)->second == 0) outputLeft << "\n";
			else outputLeft << "[    Market    ]\n";
			if (privateDevelopments.find(libraryCard)->second == 0) outputLeft << "\n";
			else outputLeft << "[   Library    ]\n";
			if (privateDevelopments.find(universityCard)->second == 0) outputLeft << "\n";
			else outputLeft << "[  University  ]\n";
			if (privateDevelopments.find(governorsHouseCard)->second == 0) outputLeft << "\n";
			else outputLeft << "[Governor's House]\n";
			if (privateDevelopments.find(chapelCard)->second == 0) outputLeft << "\n";
			else outputLeft << "[    Chapel    ]\n";
			if (privateDevelopments.find(monopolyCard)->second == 0) outputLeft << "\n";
			else if (privateDevelopments.find(monopolyCard)->second == 1) outputLeft << "[   Monopoly   ]\n";
			else outputLeft << "[   Monopoly   ] x 2\n";
			if (privateDevelopments.find(roadBuildingCard)->second == 0) outputLeft << "\n";
			else if (privateDevelopments.find(roadBuildingCard)->second == 1) outputLeft << "[Road Building ]\n";
			else outputLeft << "[Road Building ] x 2\n";
			if (privateDevelopments.find(yearOfPlentyCard)->second == 0) /*do nothing*/;
			else if (privateDevelopments.find(yearOfPlentyCard)->second == 1) outputLeft << "[Year Of Plenty]";
			else outputLeft << "[Year Of Plenty] x 2";
			GLSceneInterfaceDrawers::drawText(outputLeft.str().c_str(), outputLeft.str().length(), false, textTop, textLeft, textHeight, glTexturesRef->getTextWithBlackBackgroundTexture(), *sdlCanvasRef);
	    	glClear(GL_DEPTH_BUFFER_BIT);
	    	GLfloat oldColor[4];
	    	glGetFloatv(GL_CURRENT_COLOR, oldColor);
			Player* playerWithLargestArmy = gameStateRef->getPlayers().at(0);
			int indexOfPlayerWithLargestArmy=0;
			for (int i=0; i<gameStateRef->getNumberOfPlayers(); ++i){
				// check for largest army
				if(gameStateRef->getPlayers().at(gameStateRef->getPlayerIndex())->getOnTableDevelopments().find(soldierCard)->second>playerWithLargestArmy->getOnTableDevelopments().find(soldierCard)->second){
					playerWithLargestArmy = gameStateRef->getPlayers().at(gameStateRef->getPlayerIndex());
					indexOfPlayerWithLargestArmy = i;
				}
			}

	    	for (int i=0; i<gameStateRef->getNumberOfPlayers(); ++i)
			{
	    		int modI = (i + gameStateRef->getPlayerIndex()) % gameStateRef->getNumberOfPlayers();

		    	Player* player = gameStateRef->getPlayers().at(modI);
		    	ResourceSet playerResources = player->getResources();
		    	std::map<DevelopmentCard, int> playerOnTableDevelopments = player->getOnTableDevelopments();
				std::ostringstream outputMid;
				if (modI == gameStateRef->getPlayerIndex()) outputMid << "You (";
				outputMid << player->getName();
				if (modI == gameStateRef->getPlayerIndex()) outputMid << ")";
				outputMid << ":\n";
				outputMid << "Lx";
				if (playerResources.getWood() < 10) outputMid << "0";
				outputMid << playerResources.getWood() << " ";
				outputMid << "Sx";
				if (playerResources.getSheep() < 10) outputMid << "0";
				outputMid << playerResources.getSheep() << " ";
				outputMid << "Wx";
				if (playerResources.getWheat() < 10) outputMid << "0";
				outputMid << playerResources.getWheat() << " ";
				outputMid << "Bx";
				if (playerResources.getBrick() < 10) outputMid << "0";
				outputMid << playerResources.getBrick() << " ";
				outputMid << "Ox";
				if (playerResources.getOre() < 10) outputMid << "0";
				outputMid << playerResources.getOre() << "\n";
				outputMid << "Victory Points (" << player->getVictoryPoints(false, false) << "):\n";
				int numberOfSoldierCards = player->getOnTableDevelopments().find(soldierCard)->second;
				if (numberOfSoldierCards == 0) outputMid << "\n";
				else
				{
					if (numberOfSoldierCards < 10) outputMid << " ";
					outputMid << "  (" << numberOfSoldierCards << ") [Soldier]";
					if (numberOfSoldierCards > 1) outputMid << " x " << numberOfSoldierCards;
					outputMid << "\n";
				}

				if (playerOnTableDevelopments.find(marketCard)->second == 0) outputMid << "\n";
				else outputMid << "   (1) [Market]\n";

				if (playerOnTableDevelopments.find(libraryCard)->second == 0) outputMid << "\n";
				else outputMid << "   (1) [Library]\n";

				if (playerOnTableDevelopments.find(universityCard)->second == 0) outputMid << "\n";
				else outputMid << "   (1) [University]\n";

				if (playerOnTableDevelopments.find(governorsHouseCard)->second == 0) outputMid << "\n";
				else outputMid << "   (1) [Governor's House]\n";

				if (playerOnTableDevelopments.find(chapelCard)->second == 0) outputMid << "\n";
				else outputMid << "   (1) [Chapel]\n";
				
				if(i == indexOfPlayerWithLargestArmy && playerOnTableDevelopments.find(soldierCard)->second >= 3){
					outputMid << "   (2) [Largest Army]\n";
					player->getVictoryPoints(true, false);
				}
				else
					outputMid <<std::endl;
				outputMid << " \n";


				int numberOfSettlements = player->getNmbOfSettlementsPlaced();
				if (numberOfSettlements == 0) outputMid << "\n";
				else
				{
					if (numberOfSettlements < 10) outputMid << " ";
					outputMid << "  (" << numberOfSettlements << ") [Settlement]";
					if (numberOfSettlements > 1) outputMid << " x " << numberOfSettlements;
					outputMid << "\n";
				}

				int numberOfCities = player->getNmbOfCitiesPlaced();
				if (numberOfCities == 0) outputMid << "\n";
				else
				{
					if (numberOfCities < 5) outputMid << " ";
					outputMid << "  (" << (numberOfCities*2) << ") [City]";
					if (numberOfCities > 1) outputMid << " x " << numberOfCities;
					outputMid << "\n";
				}
				
		    	glColor3f(player->getRed(), player->getGreen(), player->getBlue());
				GLSceneInterfaceDrawers::drawText(outputMid.str().c_str(), outputMid.str().length(), false, 0.535f, 0.015f+((21+(i*26))*(0.016f*(32.0f/66))), 0.016f, glTexturesRef->getTextWithBlackBackgroundTexture(), *sdlCanvasRef);
			}
	    	glColor3f(1.0f, 1.0f, 1.0f);
	    	if (!gameStateRef->getIsRollDiceButtonEnabled())
	    	{
		    	GLSceneInterfaceDrawers::drawDie(gameStateRef->getRolledDice().at(0), gameStateRef->getRolledDice().at(2), 0.81f, 0.41f, 0.085f, glTexturesRef->getDiceTexture(), *sdlCanvasRef);
		    	GLSceneInterfaceDrawers::drawDie(gameStateRef->getRolledDice().at(1), gameStateRef->getRolledDice().at(3), 0.905f, 0.41f, 0.085f, glTexturesRef->getDiceTexture(), *sdlCanvasRef);
	    	}
	    	glColor3f(oldColor[0], oldColor[1], oldColor[2]);
	}

			/*	~DRAW~ TRADE CODE STARTS	 */

			if (clickedStartTrade)				//started trading either to player or bank
			{
				int tradeInValue = TradeIn.getWood()+TradeIn.getSheep()+TradeIn.getWheat()+TradeIn.getBrick()+TradeIn.getOre();
				int tradeForValue = TradeFor.getWood()+TradeFor.getSheep()+TradeFor.getWheat()+TradeFor.getBrick()+TradeFor.getOre();

				std::ostringstream output1;
				Player* currentPlayer = gameStateRef->getPlayers().at(gameStateRef->getPlayerIndex());
				ResourceSet playerResources = currentPlayer->getResources();

				output1 << "Player " << gameStateRef->getPlayerIndex()+1 << " (" << currentPlayer->getName() <<")" << std::endl;
				output1 << "Available resources: ";
				output1 << "Wood x " << playerResources.getWood() << " ";
				output1 << "Sheep x " << playerResources.getSheep() << " ";
				output1 << "Wheat x " << playerResources.getWheat() << " ";
				output1 << "Brick x " << playerResources.getBrick() << " ";
				output1 << "Ore x " << playerResources.getOre() << " " << std::endl;
				//output1 << "Trade instructions: OFFER 1 type of resource at a time!" << std::endl;
				//output1 << "Accepted trade: if 4:1 ratio: OFFER 4 wood & DEMAND 1 sheep or OFFER 8 wood & DEMAND 1 sheep and 1 brick; " << std::endl;
				//output1 << "NOT accepted: OFFER 4 wood, 4 sheep & DEMAND 1 ore, 1 brick." << std::endl;

				//output1 << "On Hold\n(click to start Trade):\n";
				output1 << "\t\tTRADE RESOURCES MENU" << std::endl;
				output1 << "OFFER:\t\t\t\t\t\t \t\t\tDEMAND:" << std::endl;
				output1 << "[Wood ]\t x \t" << TradeIn.getWood()  << "\t\t\t [Wood ]\t x \t" << TradeFor.getWood() << std::endl;
				output1 << "[Sheep]\t x \t" << TradeIn.getSheep() << "\t\t\t [Sheep]\t x \t" << TradeFor.getSheep() << std::endl;
				output1 << "[Wheat]\t x \t" << TradeIn.getWheat() << "\t\t\t [Wheat]\t x \t" << TradeFor.getWheat() << "\t\t\t\t\t[OFFER]" << std::endl;
				output1 << "[Brick]\t x \t" << TradeIn.getBrick() << "\t\t\t [Brick]\t x \t" << TradeFor.getBrick() << std::endl;
				output1 << "[ Ore ]\t x \t" << TradeIn.getOre()   << "\t\t\t [ Ore ]\t x \t" << TradeFor.getOre() << std::endl;
				//output1 << "\t\t\t\t\t\t\t\t\t\t[MAKE OFFER]" << std::endl;

				Player* nextPlayer;
				int modPlayer;
				//TODO: minor: Player*  nextPlayer; declared in both click and draw: make global

				//started to make a resource trade offer to players
				if (clickedTradePlayers && madeTradeOffer){
					//madeTradeOffer = false;

					if (playerResources.containsAtLeast(TradeIn)){		//check if he has enough resources of what he offers

						if (nextPlayerIndex != gameStateRef->getPlayerIndex()) {		//goes to the next player
							modPlayer = nextPlayerIndex % gameStateRef->getNumberOfPlayers();
							nextPlayerIndex = modPlayer;

							nextPlayer = gameStateRef->getPlayers().at(modPlayer);		//gets the next player
							playerResources = nextPlayer->getResources();				//get this player's resources

							output1 << "Player " << modPlayer+1 << " (" << nextPlayer->getName() <<")" << std::endl;
							output1 << "Available resources: ";
							output1 << "Wood x " << playerResources.getWood() << " ";
							output1 << "Sheep x " << playerResources.getSheep() << " ";
							output1 << "Wheat x " << playerResources.getWheat() << " ";
							output1 << "Brick x " << playerResources.getBrick() << " ";
							output1 << "Ore x " << playerResources.getOre() << " " << std::endl;
							output1 << "Do you accept the trade proposed above? ";
							
							//check if (TradeIn != 0 && TradeFor != 0 && Player.Resources.containsAtLeast(TradeIn))
							//check that the P1 has the 

							if (playerResources.containsAtLeast(TradeFor)){
								output1 << "\t[YES] / ";			//only show if it can actually do the trade
								output1 << "[NO ]" << std::endl;
							}
							else
								output1 << "\t        [NO ]" << std::endl;
						}
						else if (playerTradeCompleted){
							acceptPlayerTrade = false;
							
							//currentPlayer = gameStateRef->getPlayers().at(playerTraderIndex);
							//playerResources = currentPlayer->getResources();
							output1 << "TRADE SUCCESFULL with " << playerTraderName << std::endl;
						}
						else {				//the trade is over; check if anyone accepted
							if (PlayersAcceptedTrade.size() != 0){		//1 or more players have accepted the trade
								//show all offers and allow player to accept only 1
								output1 << "TRADE RESULT: " << PlayersAcceptedTrade.size() << " player(s) accepted your trade!";
								output1 << " Click on [TRADE] for 1 player to trade with him/her" << std::endl;
								for (int k=0; k<static_cast<int>(PlayersAcceptedTrade.size()); k++){
									output1 << "[TRADE] with " << PlayersAcceptedTrade.at(k)->getName() << std::endl;
								}
								acceptPlayerTrade = true;			//is true when system is ready to detect presing on [TRADE] 
							}
							else {	//nobody accepted the trade
								output1 << "TRADE: NOBODY accepted your trade. Choose an action from the main menu. " <<std::endl;
								/*
								TradeIn = ResourceSet(0,0,0,0,0);				//reset resource
								TradeFor = ResourceSet(0,0,0,0,0);				//reset resource
								*/
							}
						}
					}
					else{
						output1 << "You don't have enough resources to trade in. Reduce at least one of offered resources." << std::endl;
					}
				}


				//started to make a resource trade offer to BANK
				//if (madeTradeOffer && clickedTradeBank){
				if (clickedTradeBank){

					int resourceHarborMultiplier = 6;
					int generalHarborMultiplier  = 4;
					int noHarborMultiplier       = 3;
					int tradeForMultiplier       = 12;
					int generaltradeMultiplier;					//used for the final trade validation
					const int RESOURCEMULTIPLIER = 2;			//used to set resources multipliers such as woodMultiplier, sheepMultiplier, etc
					//noGeneralHarborBool = false;

					//std::cout << "OFFER TO TRADE WITH BANK" << std::endl;

					std::vector<SiteCoordinate> settlementsList = currentPlayer->getSettlements();
					std::vector<SiteCoordinate> citiesList = currentPlayer->getCities();
					//TODO: DO CITIES: major bug; now it only checks the settlement list of current player and not the cities list

					catan::CellType settlementCellType;
					//std::cout << "settlements having: " << settlementsList.size() << std::endl;
					for(int t=0; t<static_cast<int>(settlementsList.size()); t++){
						//int tradeInValue = TradeIn.getWood()+TradeIn.getSheep()+TradeIn.getWheat()+TradeIn.getBrick()+TradeIn.getOre();
						//int tradeForValue = TradeFor.getWood()+TradeFor.getSheep()+TradeFor.getWheat()+TradeFor.getBrick()+TradeFor.getOre();

						//check if they are harbor
						if (gameMapRef->isHarbor( gameMapRef->getSite(settlementsList.at(t)) )){
							noHarborAtAll = false;					//when a harbor is found use the harbor rules
							//std::cout << "You have a settlement harbor" << std::endl;
							settlementCellType = gameMapRef->getHarborType(gameMapRef->getSite(settlementsList.at(t)));

							if (settlementCellType == catan::woodHarborType){
								woodMultiplier = RESOURCEMULTIPLIER;
								output1 << "You have a settlement as a wood Harbor, 2:1 trading for wood only" << std::endl;
							}
							if (settlementCellType == catan::sheepHarborType){
								sheepMultiplier = RESOURCEMULTIPLIER;
								output1 << "You have a settlement as a sheep Harbor, 2:1 trading for sheep only" << std::endl;
							}
							if (settlementCellType == catan::wheatHarborType){
								wheatMultiplier = RESOURCEMULTIPLIER;
								output1 << "You have a settlement as a wheat Harbor, 2:1 trading for wheat only" << std::endl;
							}
							if (settlementCellType == catan::brickHarborType){
								brickMultiplier = RESOURCEMULTIPLIER;
								output1 << "You have a settlement as a brick Harbor, 2:1 trading for brick only" << std::endl;
								/*		//commented for backup only
								if (madeTradeOffer){
									std::cout << "HARBOR TRADE: offered brick. checking if valid." << std::endl;
									if (TradeIn.getBrick() * resourceHarborMultiplier == tradeForValue * tradeForMultiplier
										&& playerResources.getBrick() >= TradeIn.getBrick()){
										std::cout << "HARBOR TRADE: Valid brick purchase" << std::endl;
										//start of atomic resource exchange
										currentPlayer->setResources(currentPlayer->getResources() - TradeIn);
										currentPlayer->setResources(currentPlayer->getResources() + TradeFor);
										//end of atomic resource exchange
									}
									else
										std::cout << "HARBOR TRADE: INVALID brick purchase" << std::endl;

									madeTradeOffer = false;
								}
								*/
							}
							if (settlementCellType == catan::oreHarborType){
								oreMultiplier   = RESOURCEMULTIPLIER;
								output1 << "You have a settlement as a ore Harbor, 2:1 trading for ore only" << std::endl;
							}

							if (settlementCellType == catan::generalHarborType && noGeneralHarborBool){
								woodMultiplier  = RESOURCEMULTIPLIER+1;				//value is 3
								sheepMultiplier = RESOURCEMULTIPLIER+1;
								wheatMultiplier = RESOURCEMULTIPLIER+1;
								brickMultiplier = RESOURCEMULTIPLIER+1;
								oreMultiplier   = RESOURCEMULTIPLIER+1;
								noGeneralHarborBool = false;
								
								/*
								if (madeTradeOffer){
									if (tradeInValue * generalHarborMultiplier == tradeForValue * tradeForMultiplier
										&& playerResources.containsAtLeast(TradeIn)){
										std::cout << "HARBOR TRADE: Valid purchase" << std::endl;
										//start of atomic resource exchange
										currentPlayer->setResources(currentPlayer->getResources() - TradeIn);
										currentPlayer->setResources(currentPlayer->getResources() + TradeFor);
										//end of atomic resource exchange
									}
									madeTradeOffer = false;
								}
								*/
							}

							//START actual trading mechanism for specific resources
							if (madeTradeOffer){
								
								if (TradeIn.getWood() != 0){			//offered wood for trade
									if(woodMultiplier == RESOURCEMULTIPLIER){		//has wood harbor
										generaltradeMultiplier = resourceHarborMultiplier;
										std::cout << "Wood multiplier :" << woodMultiplier << std::endl;
									}
									else if(woodMultiplier == RESOURCEMULTIPLIER+1){ //has general harbor
										generaltradeMultiplier = generalHarborMultiplier;
										std::cout << "Wood multiplier :" << woodMultiplier << std::endl;
									}
									else{											//has no harbor; 4:1 conversion used
										generaltradeMultiplier = noHarborMultiplier;
										std::cout << "Wood multiplier :" << woodMultiplier << std::endl;
									}
									std::cout << "HARBOR TRADE: offered wood. checking if valid. GeneralTradeMul: "<< generaltradeMultiplier << std::endl;

									if(TradeIn.getWood()* generaltradeMultiplier == tradeForValue * tradeForMultiplier
									&& playerResources.getWood() >= TradeIn.getWood()){
										std::cout << "HARBOR TRADE: Valid wood purchase" << std::endl;
										//start of atomic resource exchange
										currentPlayer->setResources(currentPlayer->getResources() - TradeIn);
										currentPlayer->setResources(currentPlayer->getResources() + TradeFor);
										//end of atomic resource exchange
									}
									else{
										std::cout << "HARBOR TRADE: INVALID wood purchase" << std::endl;
										output1 << "HARBOR TRADE: INVALID wood purchase" << std::endl;
									}
									madeTradeOffer = false;
								}

								if (TradeIn.getSheep() != 0){			//offered sheep for trade
									if(sheepMultiplier == RESOURCEMULTIPLIER){		//has sheep harbor
										generaltradeMultiplier = resourceHarborMultiplier;
										std::cout << "Sheep multiplier :" << sheepMultiplier << std::endl;
									}
									else if(sheepMultiplier == RESOURCEMULTIPLIER+1){ //has general harbor
										generaltradeMultiplier = generalHarborMultiplier;
										std::cout << "Sheep multiplier :" << sheepMultiplier << std::endl;
									}
									else{											//has no harbor; 4:1 conversion used
										generaltradeMultiplier = noHarborMultiplier;
										std::cout << "Sheep multiplier :" << sheepMultiplier << std::endl;
									}
									std::cout << "HARBOR TRADE: offered sheep. checking if valid. GeneralTradeMul: "<< generaltradeMultiplier << std::endl;

									if(TradeIn.getSheep()* generaltradeMultiplier == tradeForValue * tradeForMultiplier
									&& playerResources.getSheep() >= TradeIn.getSheep()){
										std::cout << "HARBOR TRADE: Valid sheep purchase" << std::endl;
										//start of atomic resource exchange
										currentPlayer->setResources(currentPlayer->getResources() - TradeIn);
										currentPlayer->setResources(currentPlayer->getResources() + TradeFor);
										//end of atomic resource exchange
									}
									else{
										std::cout << "HARBOR TRADE: INVALID sheep purchase" << std::endl;
										output1 << "HARBOR TRADE: INVALID sheep purchase" << std::endl;
									}
									madeTradeOffer = false;
								}

								if (TradeIn.getWheat() != 0){			//offered wheat for trade
									if(wheatMultiplier == RESOURCEMULTIPLIER){		//has wheat harbor
										generaltradeMultiplier = resourceHarborMultiplier;
										std::cout << "Wheat multiplier :" << wheatMultiplier << std::endl;
									}
									else if(wheatMultiplier == RESOURCEMULTIPLIER+1){ //has general harbor
										generaltradeMultiplier = generalHarborMultiplier;
										std::cout << "Wheat multiplier :" << wheatMultiplier << std::endl;
									}
									else{											//has no harbor; 4:1 conversion used
										generaltradeMultiplier = noHarborMultiplier;
										std::cout << "Wheat multiplier :" << wheatMultiplier << std::endl;
									}
									std::cout << "HARBOR TRADE: offered wheat. checking if valid. GeneralTradeMul: "<< generaltradeMultiplier << std::endl;

									if(TradeIn.getWheat()* generaltradeMultiplier == tradeForValue * tradeForMultiplier
									&& playerResources.getWheat() >= TradeIn.getWheat()){
										std::cout << "HARBOR TRADE: Valid wheat purchase" << std::endl;
										//start of atomic resource exchange
										currentPlayer->setResources(currentPlayer->getResources() - TradeIn);
										currentPlayer->setResources(currentPlayer->getResources() + TradeFor);
										//end of atomic resource exchange
									}
									else{
										std::cout << "HARBOR TRADE: INVALID wheat purchase" << std::endl;
										output1 << "HARBOR TRADE: INVALID wheat purchase" << std::endl;
									}
									madeTradeOffer = false;
								}

								if (TradeIn.getBrick() != 0){			//offered brick for trade
									if(brickMultiplier == RESOURCEMULTIPLIER){		//has brick harbor
										generaltradeMultiplier = resourceHarborMultiplier;
										std::cout << "Brick multiplier :" << brickMultiplier << std::endl;
									}
									else if(brickMultiplier == RESOURCEMULTIPLIER+1){ //has general harbor
										generaltradeMultiplier = generalHarborMultiplier;
										std::cout << "Brick multiplier :" << brickMultiplier << std::endl;
									}
									else{											//has no harbor; 4:1 conversion used
										generaltradeMultiplier = noHarborMultiplier;
										std::cout << "Brick multiplier :" << brickMultiplier << std::endl;
									}
									std::cout << "HARBOR TRADE: offered brick. checking if valid. GeneralTradeMul: "<< generaltradeMultiplier << std::endl;

									if(TradeIn.getBrick()* generaltradeMultiplier == tradeForValue * tradeForMultiplier
									&& playerResources.getBrick() >= TradeIn.getBrick()){
										std::cout << "HARBOR TRADE: Valid brick purchase" << std::endl;
										//start of atomic resource exchange
										currentPlayer->setResources(currentPlayer->getResources() - TradeIn);
										currentPlayer->setResources(currentPlayer->getResources() + TradeFor);
										//end of atomic resource exchange
									}
									else{
										std::cout << "HARBOR TRADE: INVALID brick purchase" << std::endl;
										output1 << "HARBOR TRADE: INVALID brick purchase" << std::endl;
									}
									madeTradeOffer = false;
								}

								if (TradeIn.getOre() != 0){			//offered ore for trade
									if(oreMultiplier == RESOURCEMULTIPLIER){		//has ore harbor
										generaltradeMultiplier = resourceHarborMultiplier;
										std::cout << "Ore multiplier :" << oreMultiplier << std::endl;
									}
									else if(oreMultiplier == RESOURCEMULTIPLIER+1){ //has general harbor
										generaltradeMultiplier = generalHarborMultiplier;
										std::cout << "Ore multiplier :" << oreMultiplier << std::endl;
									}
									else{											//has no harbor; 4:1 conversion used
										generaltradeMultiplier = noHarborMultiplier;
										std::cout << "Ore multiplier :" << oreMultiplier << std::endl;
									}
									std::cout << "HARBOR TRADE: offered ore. checking if valid. GeneralTradeMul: "<< generaltradeMultiplier << std::endl;

									if(TradeIn.getOre()* generaltradeMultiplier == tradeForValue * tradeForMultiplier
									&& playerResources.getOre() >= TradeIn.getOre()){
										std::cout << "HARBOR TRADE: Valid ore purchase" << std::endl;
										//start of atomic resource exchange
										currentPlayer->setResources(currentPlayer->getResources() - TradeIn);
										currentPlayer->setResources(currentPlayer->getResources() + TradeFor);
										//end of atomic resource exchange
									}
									else{
										std::cout << "HARBOR TRADE: INVALID ore purchase" << std::endl;
										output1 << "HARBOR TRADE: INVALID ore purchase" << std::endl;
									}
									madeTradeOffer = false;
								}

								/*		no need for specific general port trading, done in each resource case.
								if(!noGeneralHarborBool){			// general harbor trading occured
									generaltradeMultiplier = generalHarborMultiplier;

									if (tradeInValue * generaltradeMultiplier == tradeForValue * tradeForMultiplier
										&& playerResources.containsAtLeast(TradeIn)){
										std::cout << "HARBOR TRADE: Valid general port purchase" << std::endl;
										//start of atomic resource exchange
										currentPlayer->setResources(currentPlayer->getResources() - TradeIn);
										currentPlayer->setResources(currentPlayer->getResources() + TradeFor);
										//end of atomic resource exchange
									}
									madeTradeOffer = false;
								}
								*/
							}		//END of trading mechanism for resource trading
						}		//END of checking all harbors for this player

						//4:1 ratio used only there is no harbor at all
						if (madeTradeOffer && noHarborAtAll){
							std::cout << "HARBOR TRADE: checking if valid 4:1 trade." << std::endl;
							if (tradeInValue * noHarborMultiplier == tradeForValue * tradeForMultiplier
								&& playerResources.containsAtLeast(TradeIn)){
									std::cout << "HARBOR TRADE: Valid 4:1 purchase" << std::endl;
								//start of atomic resource exchange
								currentPlayer->setResources(currentPlayer->getResources() - TradeIn);
								currentPlayer->setResources(currentPlayer->getResources() + TradeFor);
								//end of atomic resource exchange
							}
							else{
								output1 << "HARBOR TRADE: INVALID ore purchase" << std::endl;
								std::cout << "HARBOR TRADE: INVALID 4:1 trade" << std::endl;
							}
							madeTradeOffer = false;
						}
					}	//END of checking all settlements for this player

					//TODO: DO CITIES: major bug; now it only checks the settlement list of current player and not the cities list
					//optional. Add error messaging.

					if(noGeneralHarborBool)		//4:1 only available if there is no general harbor.
						output1 << "DEFAULT 4:1 trading available " << std::endl;
					else
						output1 << "You have a settlement as a general Harbor, 3:1 trading default " << std::endl;

					//END CLAUDIU's TRADING code

					catan::CellType cityCellType;
					for(int t=0; t<static_cast<int>(citiesList.size()); t++){
						//check if they are harbor
						//if (gameMapRef->isHarbor( gameMapRef->getSite(settlementsList.at(t)) )){
						if (gameMapRef->isHarbor( gameMapRef->getSite(citiesList.at(t)) )){
							std::cout << "You have a city harbor" << std::endl;
							cityCellType = gameMapRef->getHarborType(gameMapRef->getSite(citiesList.at(t)));

							if (cityCellType == catan::generalHarborType){
								std::cout << "You have a city generalHarborType" << std::endl;
							}
							else if (cityCellType == catan::woodHarborType){
								std::cout << "You have a city woodHarborType" << std::endl;
							}
							else if (cityCellType == catan::sheepHarborType){
								std::cout << "You have a city sheepHarborType" << std::endl;
							}
							else if (cityCellType == catan::wheatHarborType){
								std::cout << "You have a city wheatHarborType" << std::endl;
							}
							else if (cityCellType == catan::brickHarborType){
								std::cout << "You have a city brickHarborType" << std::endl;
							}
							else if (cityCellType == catan::oreHarborType){
								std::cout << "You have a city oreHarborType" << std::endl;
							}
						}
					}
				}

				GLSceneInterfaceDrawers::drawText(output1.str().c_str(), output1.str().length(), false, textTop, textLeft, textHeight, glTexturesRef->getTextWithBlackBackgroundTexture(), *sdlCanvasRef);
			}

		GLSceneOrthogonalMode::end();
    }

	else
	{
    	glClear(GL_DEPTH_BUFFER_BIT);
		std::ostringstream endGame;
		endGame << "END GAME! The winner is: "<< gameStateRef->getPlayers().at(gameStateRef->getPlayerIndex())->getName()<<std::endl;
		endGame << "Thank you for playing Settlers Of Catan"<<std::endl;
		GLSceneOrthogonalMode::begin(*sdlCanvasRef);
		GLSceneInterfaceDrawers::drawText(endGame.str().c_str(), endGame.str().length(), false, textTop, textLeft, textHeight+0.03, glTexturesRef->getTextWithBlackBackgroundTexture(), *sdlCanvasRef);
		GLSceneOrthogonalMode::end();
	}

    SDL_GL_SwapBuffers();
    if (timer.secondsSinceReference() > 1.0f/25) 
    {
    	frame++;
    	timer.resetReference();
    }
}

void GLScene::click(int x, int y)
{
	//y equation, for x=1 to 15: 0.6054460246*x^2 + 19.63446994*x + 13.52352941
	//0.606, 19.6, 13.5

	float xRatio = (sdlCanvasRef->getWindowUnitWidth() - sdlCanvasRef->getClientUnitWidth())/2;
	float yRatio = (sdlCanvasRef->getWindowUnitHeight() - sdlCanvasRef->getClientUnitHeight())/2;
	float clientX = (x - xRatio*sdlCanvasRef->getWidth())*(sdlCanvasRef->getWindowUnitWidth()/sdlCanvasRef->getWidth());
	float clientY = (y - yRatio*sdlCanvasRef->getHeight())*(sdlCanvasRef->getWindowUnitHeight()/sdlCanvasRef->getHeight());
	Player *currentPlayer = gameStateRef->getPlayers().at(gameStateRef->getPlayerIndex());
	//float clientYToUnit = clientY * 4 / 3;
	if (gameStateRef->getIsPreStartGame())
	{
		if (clientX > 0.8f && clientX < 1.0f &&
				clientY > 0.0f && clientY < 0.05f)
		{
			gameMapRef->reset();
		}
		else if (clientX > 0.8f && clientX < 1.0f &&
				clientY > 0.05f && clientY < 0.10f)
		{
			turnCounter++;
			std::cout << "turn #"<<turnCounter<<std::endl;
			gameStateRef->setIsPreStartGame(false);
			gameStateRef->setIsRollDiceButtonEnabled(false);
			gameStateRef->setIsBuyRoadButtonEnabled(true);
			gameStateRef->setIsBuySettlementButtonEnabled(true);
			gameStateRef->setIsCityUpgradeButtonPressed(false);
			gameStateRef->setIsBuyDevelopmentCardButtonEnabled(false);
			gameStateRef->setIsPlayerTradeButtonEnabled(false);
			gameStateRef->setIsBankTradeButtonEnabled(false);
			gameStateRef->setIsEndTurnButtonEnabled(false);
		}
		else
		{
			float calcX = (0.4f-clientX)/(0.09375f*clientY + 0.1335f);
			//float calcY = (9.107f*clientY*clientY - 18.486f*clientY + 3.687f);
			//-3.8008346998012343 + 20.05063303391713x -15.795532422655647x^2 + 8.878439171845189x^3
			float calcY = 8.878439171845189*clientY*clientY*clientY - 15.795532422655647*clientY*clientY + 20.05063303391713*clientY - 3.8008346998012343; 
			float calcX2 = -calcX*2 + 3;
			float calcY2 = calcY + calcX + 3;
			std::cout << clientX << ", " << clientY << "; " << calcX << ", " << calcY << "; " << calcX2 << ", " << calcY2 << std::endl;
		}
	}
	else
	{
		if (clientX>0.8f && clientX<=1.0f)
		{
			if (gameStateRef->getIsRollDiceButtonEnabled() && clientY>=0.0f && clientY<0.05f)
			{
				clickedStartTrade = false;			//to counter Trade menu to appear
				clickedTradePlayers = false;
				madeTradeOffer = false;
				clickedTradeBank = false;
				acceptPlayerTrade = false;			//using in Claudiu's Player trade
				gameStateRef->rollDice();
				int rolledValue = gameStateRef->getRolledDice()[0] + gameStateRef->getRolledDice()[1];
				std::vector<Cell*> numberMatchedCells = gameMapRef->getCellsOfNumber(CellNumber(static_cast<CellNumber::Enum_CellNumber>(rolledValue)));
				std::vector<Player*> players = gameStateRef->getPlayers();
				for (std::vector<Player*>::const_iterator playerIterator = players.begin(); playerIterator != players.end(); ++playerIterator)
				{
					Player* playerRef = *playerIterator;
					std::vector<SiteCoordinate> settlements = playerRef->getSettlements();
					for (std::vector<SiteCoordinate>::const_iterator settlementIterator = settlements.begin(); settlementIterator != settlements.end(); ++settlementIterator)
					{
						std::map<HorizontalCardinal, Cell*> playerCells = gameMapRef->getCellsNeighboringSite(gameMapRef->getSite(*settlementIterator));
						for (std::vector<Cell*>::const_iterator numberMatchedCellIterator = numberMatchedCells.begin(); numberMatchedCellIterator != numberMatchedCells.end(); ++numberMatchedCellIterator)
						{
							Cell* numberMatchedCellRef = *numberMatchedCellIterator;
							for (std::map<HorizontalCardinal, Cell*>::const_iterator playerCellIterator = playerCells.begin(); playerCellIterator != playerCells.end(); ++playerCellIterator)
							{
								if (numberMatchedCellRef->getCoordinate() == playerCellIterator->second->getCoordinate())
								{
									playerRef->setResources(playerRef->getResources() + ResourceSet(numberMatchedCellRef->getType()));
								}
							}
						}
					}
					std::vector<SiteCoordinate> cities = playerRef->getCities();
					for (std::vector<SiteCoordinate>::const_iterator cityIterator = cities.begin(); cityIterator != cities.end(); ++cityIterator)
					{
						std::map<HorizontalCardinal, Cell*> playerCells = gameMapRef->getCellsNeighboringSite(gameMapRef->getSite(*cityIterator));
						for (std::vector<Cell*>::const_iterator numberMatchedCellIterator = numberMatchedCells.begin(); numberMatchedCellIterator != numberMatchedCells.end(); ++numberMatchedCellIterator)
						{
							Cell* numberMatchedCellRef = *numberMatchedCellIterator;
							for (std::map<HorizontalCardinal, Cell*>::const_iterator playerCellIterator = playerCells.begin(); playerCellIterator != playerCells.end(); ++playerCellIterator)
							{
								if (numberMatchedCellRef->getCoordinate() == playerCellIterator->second->getCoordinate())
								{
									playerRef->setResources(playerRef->getResources() + (ResourceSet(numberMatchedCellRef->getType())*2));
								}
							}
						}
					}
				}
				std::cout << std::endl;
				gameStateRef->setIsRollDiceButtonEnabled(false);
				gameStateRef->setIsBuyRoadButtonEnabled(true);
				gameStateRef->setIsBuySettlementButtonEnabled(true);
				gameStateRef->setIsCityUpgradeButtonEnabled(true);
				gameStateRef->setIsBuyDevelopmentCardButtonEnabled(true);
				gameStateRef->setIsPlayerTradeButtonEnabled(true);
				gameStateRef->setIsBankTradeButtonEnabled(true);
				gameStateRef->setIsEndTurnButtonEnabled(true);
			}

			else if (gameStateRef->getIsBuyRoadButtonEnabled() && clientY>=0.05f && clientY<0.1f)
			{
				clickedStartTrade = false;			//to counter Trade menu to appear
				clickedTradePlayers = false;
				madeTradeOffer = false;
				clickedTradeBank = false;
				acceptPlayerTrade = false;			//using in Claudiu's Player trade
				if (gameStateRef->canAddRoad(*currentPlayer))	// sufficient resources to buy a road or less then 2 roads
				{
					std::cout << "Click where to put the road #";
					std::cout << (currentPlayer->getNmbOfRoadsPlaced()+1)<< ".\n";
					gameStateRef->setIsRollDiceButtonEnabled(false);
					gameStateRef->setIsBuyRoadButtonPressed(true);
					gameStateRef->setIsBuySettlementButtonEnabled(false);
					gameStateRef->setIsBuyDevelopmentCardButtonEnabled(false);
					gameStateRef->setIsPlayerTradeButtonEnabled(false);
					gameStateRef->setIsBankTradeButtonEnabled(false);
					gameStateRef->setIsEndTurnButtonEnabled(false);
				}
			}// End of Display when Buy Road button is clicked

			else if (gameStateRef->getIsBuySettlementButtonEnabled() && clientY>=0.1f && clientY<0.15f)
			{
				clickedStartTrade = false;			//to counter Trade menu to appear
				clickedTradePlayers = false;
				madeTradeOffer = false;
				clickedTradeBank = false;
				acceptPlayerTrade = false;			//using in Claudiu's Player trade
				// gameStateRef->setIsBuySettlementButtonPressed(true);
				if(gameStateRef->canAddSettlement(*currentPlayer)){ // sufficient resources to buy a settlement or owns less then 2 settlements
					std::cout << "Click where to put the settlement #";
					std::cout << (currentPlayer->getNmbOfSettlementsPlaced()+1)<< ".\n";
					gameStateRef->setIsBuySettlementButtonPressed(true);
					gameStateRef->setIsBuyRoadButtonEnabled(false);
					gameStateRef->setIsCityUpgradeButtonEnabled(false);
					gameStateRef->setIsBuyDevelopmentCardButtonEnabled(false);
					gameStateRef->setIsPlayerTradeButtonEnabled(false);
					gameStateRef->setIsBankTradeButtonEnabled(false);
					gameStateRef->setIsEndTurnButtonEnabled(false);
				}
				else
					std::cout << "NEED RESOURCES FOR A SETTLEMENT!\n";
			} // End of Buy Settlement is clicked

			// City upgrade button
			else if (gameStateRef->getIsCityUpgradeButtonEnabled() && clientY>=0.15f && clientY<0.2f)
			{
				clickedStartTrade = false;			//to counter Trade menu to appear
				clickedTradePlayers = false;
				madeTradeOffer = false;
				clickedTradeBank = false;
				acceptPlayerTrade = false;			//using in Claudiu's Player trade
				if(gameStateRef->canCityUpgrade(*currentPlayer)){ // sufficient resources for a City
					std::cout << "City bought\n";
					gameStateRef->setIsCityUpgradeButtonPressed(true);
					gameStateRef->setIsBuyRoadButtonEnabled(false);
					gameStateRef->setIsBuySettlementButtonEnabled(false);
					gameStateRef->setIsBuyDevelopmentCardButtonEnabled(false);
					gameStateRef->setIsPlayerTradeButtonEnabled(false);
					gameStateRef->setIsBankTradeButtonEnabled(false);
					gameStateRef->setIsEndTurnButtonEnabled(false);
				}
				else
					std::cout << "Unable to upgrade to city!\n";
			}// End of City Upgrade button is clicked

			else if (gameStateRef->getIsBuyDevelopmentCardButtonEnabled() && clientY>=0.2f && clientY<0.25f)
			{
				clickedStartTrade = false;			//to counter Trade menu to appear
				clickedTradePlayers = false;
				madeTradeOffer = false;
				clickedTradeBank = false;
				acceptPlayerTrade = false;			//using in Claudiu's Player trade
				if(currentPlayer->getResources().containsAtLeast(catan::developmentCost)){ // sufficient resources for a Development
					if(gameStateRef->getDevelopmentDeck().size()>0)
					{ // deck developments
						// add to its private development deck
						currentPlayer->addDevelopmentCard(gameStateRef->getDevelopmentDeck().back());
						// erase that card from the game development deck
						gameStateRef->getDevelopmentDeck().pop_back();
						std::cout << "Development bought\n";
						std::cout << "now the size of the dev deck is:"<<gameStateRef->getDevelopmentDeck().size()<<std::endl;
					}
					else
						std::cout << "NO MORE DEVELOPMENTS TO BUY!";
				}
				else
					std::cout << "NEED RESOURCES FOR DEV!\n";
				gameStateRef->setIsRollDiceButtonEnabled(false);
				gameStateRef->setIsBuyRoadButtonEnabled(true);
				gameStateRef->setIsBuySettlementButtonEnabled(true);
				gameStateRef->setIsBuyDevelopmentCardButtonEnabled(true);
				gameStateRef->setIsPlayerTradeButtonEnabled(true);
				gameStateRef->setIsBankTradeButtonEnabled(true);
				gameStateRef->setIsEndTurnButtonEnabled(true);
			}// End of Buy Development button is clicked

			//start [PLAYER] trading
			else if (gameStateRef->getIsPlayerTradeButtonEnabled() && clientY>=0.25f && clientY<0.3f)
			{
				TradeIn = ResourceSet(0,0,0,0,0);				//reset resource
				TradeFor = ResourceSet(0,0,0,0,0);				//reset resource

				woodMultiplier  = 1;
				sheepMultiplier = 1;
				wheatMultiplier = 1;
				brickMultiplier = 1;
				oreMultiplier   = 1;

				clickedStartTrade = true;
				madeTradeOffer = false;
				acceptPlayerTrade = false;
				std::cout << "Clicked on Player Trade" << std::endl;
				clickedTradePlayers = true;
				clickedTradeBank = false;
				//gameStateRef->setIsBankTradeButtonEnabled(false);			//disable bank trade

			}
			//start [BANK] trading
			else if (gameStateRef->getIsBankTradeButtonEnabled() && clientY>=0.3f && clientY<0.35f)
			{
				TradeIn = ResourceSet(0,0,0,0,0);				//reset resource
				TradeFor = ResourceSet(0,0,0,0,0);				//reset resource

				clickedStartTrade = true;
				madeTradeOffer = false;
				acceptPlayerTrade = false;
				std::cout << "Clicked on Bank Trade" << std::endl;
				clickedTradeBank = true;
				clickedTradePlayers = false;
				noGeneralHarborBool = true;		//start with the assumption that there is no general harbor; set false when general harbor is found for that player
				noHarborAtAll = true;
				//gameStateRef->setIsPlayerTradeButtonEnabled(false);			//disable players trade
				
				woodMultiplier  = 4;
				sheepMultiplier = 4;
				wheatMultiplier = 4;
				brickMultiplier = 4;
				oreMultiplier   = 4;

				// add harbor settlements manually
				//Player* currentPlayer = gameStateRef->getPlayers().at(gameStateRef->getPlayerIndex());
				//currentPlayer->addSettlement(SiteCoordinate(x2,y4,horizontalCL));
				//currentPlayer->addSettlement(SiteCoordinate(x1,y5,horizontalCL));
				//currentPlayer->addSettlement(SiteCoordinate(x2,y5,horizontalCL));			//adds a harbor
				//currentPlayer->addSettlement(SiteCoordinate(x3,y5,horizontalCL));
			
				//std::cout << "ADDED a harbor settlement" << std::endl;
			}
			// End turn button clicked
			else if (gameStateRef->getIsEndTurnButtonEnabled() && clientY>=0.35f && clientY<0.4f)
			{
				clickedStartTrade = false;			//to counter Trade menu to appear
				clickedTradePlayers = false;
				madeTradeOffer = false;
				clickedTradeBank = false;
				acceptPlayerTrade = false;			//using in Claudiu's Player trade


				if(gameStateRef->isTheEnd()){
					gameStateRef->setIsRollDiceButtonEnabled(false);
					gameStateRef->setIsBuyRoadButtonEnabled(false);
					gameStateRef->setIsBuySettlementButtonEnabled(false);
					gameStateRef->setIsEndTurnButtonEnabled(false);
					std::cout<<"Player:"<<currentPlayer->getName()<<std::endl;
					std::cout<<"END GAME! The winner is:"<<currentPlayer->getVictoryPoints(false, false)<<std::endl;
				}
				else{
					gameStateRef->nextPlayer();
					currentPlayer = gameStateRef->getPlayers().at(gameStateRef->getPlayerIndex()); // next player is now the current player
					turnCounter++;
					std::cout<<"current player:"<<currentPlayer->getName()<<std::endl;
					std::cout<<"turn #:"<<turnCounter<<std::endl;
					if(turnCounter > static_cast<int>(gameStateRef->getPlayers().size()))
					{
						gameStateRef->setIsRollDiceButtonEnabled(true);
						gameStateRef->setIsBuyRoadButtonEnabled(false);
						gameStateRef->setIsBuySettlementButtonEnabled(false);
						gameStateRef->setIsEndTurnButtonEnabled(false);
					}
					else{
						gameStateRef->setIsRollDiceButtonEnabled(false);
						gameStateRef->setIsBuyRoadButtonEnabled(true);
						gameStateRef->setIsBuySettlementButtonEnabled(true);
						gameStateRef->setIsEndTurnButtonEnabled(true);
					}
				}
			gameStateRef->setIsCityUpgradeButtonEnabled(false);
			gameStateRef->setIsBuyDevelopmentCardButtonEnabled(false);
			gameStateRef->setIsPlayerTradeButtonEnabled(false);
			gameStateRef->setIsBankTradeButtonEnabled(false);
			}
		}
		
		// play development card
		if(!clickedStartTrade && clientX>0 && clientX<0.17)
		{
			std::map<DevelopmentCard, int> privateDevelopments = currentPlayer->getPrivateDevelopments();

			float stringCharWidth = 10;
			float topCharPosition = 3;
			float leftCharPosition = 0;

			float leftDev = textLeft+(leftCharPosition*textWidth);
			float rightDev = textLeft+((leftCharPosition + stringCharWidth)*textWidth);
			float topDev = textTop + textHeight*topCharPosition;
			float bottomDev = textTop + textHeight*(topCharPosition+1);

			//detecting the click on soldier
			if (leftDev < clientX && rightDev > clientX && topDev < clientY && bottomDev > clientY && currentPlayer->canPlayDevelopmentCard(privateDevelopments.find(soldierCard)->first)){
				std::cout << "Clicked on Soldier" << std::endl;
				currentPlayer->playDevelopmentCard(privateDevelopments.find(soldierCard)->first);
			}

			topCharPosition = 4; // next line
			topDev = textTop + textHeight*topCharPosition;
			bottomDev = textTop + textHeight*(topCharPosition+1);

			if(leftDev < clientX && rightDev > clientX && topDev < clientY && bottomDev > clientY && currentPlayer->canPlayDevelopmentCard(privateDevelopments.find(marketCard)->first)){
				std::cout << "Clicked on Market" << std::endl;
				currentPlayer->playDevelopmentCard(privateDevelopments.find(marketCard)->first);
			}

			topCharPosition = 5; // next line
			topDev = textTop + textHeight*topCharPosition;
			bottomDev = textTop + textHeight*(topCharPosition+1);

			if(leftDev < clientX && rightDev > clientX && topDev < clientY && bottomDev > clientY && currentPlayer->canPlayDevelopmentCard(privateDevelopments.find(libraryCard)->first)){
				std::cout << "Clicked on Library" << std::endl;
				currentPlayer->playDevelopmentCard(privateDevelopments.find(libraryCard)->first);
			}

			topCharPosition = 6; // next line
			topDev = textTop + textHeight*topCharPosition;
			bottomDev = textTop + textHeight*(topCharPosition+1);

			if(leftDev < clientX && rightDev > clientX && topDev < clientY && bottomDev > clientY && currentPlayer->canPlayDevelopmentCard(privateDevelopments.find(universityCard)->first)){
				std::cout << "Clicked on University" << std::endl;
				currentPlayer->playDevelopmentCard(privateDevelopments.find(universityCard)->first);
			}

			topCharPosition = 7; // next line
			topDev = textTop + textHeight*topCharPosition;
			bottomDev = textTop + textHeight*(topCharPosition+1);

			if(leftDev < clientX && rightDev > clientX && topDev < clientY && bottomDev > clientY && currentPlayer->canPlayDevelopmentCard(privateDevelopments.find(governorsHouseCard)->first)){
				std::cout << "Clicked on Governor's Hous" << std::endl;
				currentPlayer->playDevelopmentCard(privateDevelopments.find(governorsHouseCard)->first);
			}

			topCharPosition = 8; // next line
			topDev = textTop + textHeight*topCharPosition;
			bottomDev = textTop + textHeight*(topCharPosition+1);

			if(leftDev < clientX && rightDev > clientX && topDev < clientY && bottomDev > clientY && currentPlayer->canPlayDevelopmentCard(privateDevelopments.find(chapelCard)->first)){
				std::cout << "Clicked on Chapel" << std::endl;
				currentPlayer->playDevelopmentCard(privateDevelopments.find(chapelCard)->first);
			}

			topCharPosition = 9; // next line
			topDev = textTop + textHeight*topCharPosition;
			bottomDev = textTop + textHeight*(topCharPosition+1);

			if(leftDev < clientX && rightDev > clientX && topDev < clientY && bottomDev > clientY && currentPlayer->canPlayDevelopmentCard(privateDevelopments.find(monopolyCard)->first)){
				std::cout << "Clicked on Monopoly" << std::endl;
				currentPlayer->playDevelopmentCard(privateDevelopments.find(monopolyCard)->first);
				ResourceSet resourceSet(0, 0, 0, 0, 0);
				std::vector<Player*> players = gameStateRef->getPlayers();
				for (std::vector<Player*>::const_iterator playerIterator = players.begin(); playerIterator != players.end(); ++playerIterator)
				{
					resourceSet = resourceSet + (*playerIterator)->getResources();
					(*playerIterator)->setResources(resourceEmpty);
				}
				currentPlayer->setResources(resourceSet);
			}

			topCharPosition = 10; // next line
			topDev = textTop + textHeight*topCharPosition;
			bottomDev = textTop + textHeight*(topCharPosition+1);

			if(leftDev < clientX && rightDev > clientX && topDev < clientY && bottomDev > clientY && currentPlayer->canPlayDevelopmentCard(privateDevelopments.find(roadBuildingCard)->first)){
				std::cout << "Clicked on Road Building" << std::endl;
				currentPlayer->playDevelopmentCard(privateDevelopments.find(roadBuildingCard)->first);
				gameStateRef->setIsRollDiceButtonEnabled(false);
				gameStateRef->setIsBuyRoadButtonPressed(true);
				gameStateRef->setIsBuySettlementButtonEnabled(false);
				gameStateRef->setIsBuyDevelopmentCardButtonEnabled(false);
				gameStateRef->setIsPlayerTradeButtonEnabled(false);
				gameStateRef->setIsBankTradeButtonEnabled(false);
				gameStateRef->setIsEndTurnButtonEnabled(false);
				currentPlayer->setResources(currentPlayer->getResources() + roadCost);
			}

			topCharPosition = 11; // next line
			topDev = textTop + textHeight*topCharPosition;
			bottomDev = textTop + textHeight*(topCharPosition+1);

			if(leftDev < clientX && rightDev > clientX && topDev < clientY && bottomDev > clientY && currentPlayer->canPlayDevelopmentCard(privateDevelopments.find(yearOfPlentyCard)->first)){
				std::cout << "Clicked on Year of Plenty" << std::endl;
				currentPlayer->playDevelopmentCard(privateDevelopments.find(yearOfPlentyCard)->first);
				currentPlayer->setResources(currentPlayer->getResources() + ResourceSet(1, 1, 1, 1, 1));
			}
		}// end play development card

		// when the buy settlement or upgrade city is pressed
		if (gameStateRef->getIsBuySettlementButtonPressed() || gameStateRef->getIsCityUpgradeButtonPressed())
		{
			//clickedStartTrade = false;			//to counter Trade menu to appear
			float calcX = (0.4f-clientX)/(0.09375f*clientY + 0.1335f);
			float calcY = 8.878439171845189*clientY*clientY*clientY - 15.795532422655647*clientY*clientY + 20.05063303391713*clientY - 3.8008346998012343; 
			float calcX2 = -calcX*2 + 3;
			float calcY2 = calcY + calcX + 3;
			float siteOffsetXs[6] = {0.6667f, 0.3333f, -0.3333f, -0.6667f, -0.3333f, 0.3333f};
			float siteOffsetYs[6] = {-0.3333f, -0.6667f, -0.3333f, 0.3333f, 0.6667f, 0.3333f};
			for (int j=0; j<6; ++j)
			{
				for (int i=0; i<6; ++i)
				{
					for (int k=0; k<6; k+=3)
					{
						if (calcX2 > (i+siteOffsetXs[k])-0.1f && calcX2 < (i+siteOffsetXs[k])+0.1f &&
						    calcY2 > (j+siteOffsetYs[k])-0.1f && calcY2 < (j+siteOffsetYs[k])+0.1f)
						{
							CoordinateX coordinateX = CoordinateX(static_cast<CoordinateX::Enum_CoordinateX>(i));
							CoordinateY coordinateY = CoordinateY(static_cast<CoordinateY::Enum_CoordinateY>(j));
							HorizontalCardinal horizontalCardinal = HorizontalCardinal(static_cast<HorizontalCardinal::Enum_HorizontalCardinal>(k*60));
							if (SiteCoordinate::canInit(coordinateX, coordinateY, horizontalCardinal))
							{
								SiteCoordinate siteCoordinate = SiteCoordinate(coordinateX, coordinateY, horizontalCardinal);
								if (
										(gameStateRef->getIsCityUpgradeButtonPressed() && gameStateRef->canCityUpgrade(*currentPlayer, *gameMapRef, siteCoordinate)) ||
										(gameStateRef->getIsBuySettlementButtonPressed() && gameStateRef->canAddSettlement(*currentPlayer, *gameMapRef, siteCoordinate))
								   )
								{
									if (gameStateRef->getIsBuySettlementButtonPressed())
									{
										currentPlayer->addSettlement(siteCoordinate);
										gameStateRef->setIsBuySettlementButtonPressed(false);
									}
									else
									{
										currentPlayer->upgradeSettlement(siteCoordinate);
										gameStateRef->setIsCityUpgradeButtonPressed(false);
									}
									// round >=2
									if(turnCounter > gameStateRef->getNumberOfPlayers()){
										gameStateRef->setIsBuyRoadButtonEnabled(true);
										gameStateRef->setIsBuySettlementButtonEnabled(true);
										gameStateRef->setIsCityUpgradeButtonEnabled(true);
										gameStateRef->setIsBuyDevelopmentCardButtonEnabled(true);
										gameStateRef->setIsPlayerTradeButtonEnabled(true);
										gameStateRef->setIsBankTradeButtonEnabled(true);
										gameStateRef->setIsEndTurnButtonEnabled(true);
									}
									// first round
									else{
										if(currentPlayer->getNmbOfSettlementsPlaced()<2){
											if(currentPlayer->getNmbOfRoadsPlaced()<2)
												gameStateRef->setIsBuyRoadButtonEnabled(true);
											else
												gameStateRef->setIsBuyRoadButtonEnabled(false);
											gameStateRef->setIsBuySettlementButtonEnabled(true);
											gameStateRef->setIsEndTurnButtonEnabled(false);
										}
										else{
											if(currentPlayer->getNmbOfRoadsPlaced()<2)
												gameStateRef->setIsBuyRoadButtonEnabled(true);
											else
												gameStateRef->setIsBuyRoadButtonEnabled(false);
											gameStateRef->setIsBuySettlementButtonEnabled(false);
											gameStateRef->setIsEndTurnButtonEnabled(true);
										}
										gameStateRef->setIsCityUpgradeButtonEnabled(false);
										gameStateRef->setIsBuyDevelopmentCardButtonEnabled(false);
										gameStateRef->setIsPlayerTradeButtonEnabled(false);
										gameStateRef->setIsBankTradeButtonEnabled(false);
									}
								}
							}
						}
					}
				}
			}
		}
		
		if (gameStateRef->getIsBuyRoadButtonPressed())
		{
			//clickedStartTrade = false;			//to counter Trade menu to appear
			float calcX = (0.4f-clientX)/(0.09375f*clientY + 0.1335f);
			float calcY = 8.878439171845189*clientY*clientY*clientY - 15.795532422655647*clientY*clientY + 20.05063303391713*clientY - 3.8008346998012343; 
			float calcX2 = -calcX*2 + 3;
			float calcY2 = calcY + calcX + 3;
			float pathOffsetXs[6] = {0.5f, 0.0f, -0.5f, -0.5f, 0.0f, 0.5f};
			float pathOffsetYs[6] = {-0.5f, -0.5f, 0.0f, 0.5f, 0.5f, 0.0f};
			for (int j=0; j<6; ++j)
			{
				for (int i=0; i<6; ++i)
				{
					for (int k=0; k<6; k+=2)
					{
						if (calcX2 > (i+pathOffsetXs[k])-0.1f && calcX2 < (i+pathOffsetXs[k])+0.1f &&
						    calcY2 > (j+pathOffsetYs[k])-0.1f && calcY2 < (j+pathOffsetYs[k])+0.1f)
						{
							CoordinateX coordinateX = CoordinateX(static_cast<CoordinateX::Enum_CoordinateX>(i));
							CoordinateY coordinateY = CoordinateY(static_cast<CoordinateY::Enum_CoordinateY>(j));
							VerticalCardinal verticalCardinal = VerticalCardinal(static_cast<VerticalCardinal::Enum_VerticalCardinal>(k*60+30));
							if (PathCoordinate::canInit(coordinateX, coordinateY, verticalCardinal))
							{
								PathCoordinate pathCoordinate = PathCoordinate(coordinateX, coordinateY, verticalCardinal);
								if (gameStateRef->getIsBuyRoadButtonPressed() && gameStateRef->canAddRoad(*currentPlayer, *gameMapRef, pathCoordinate))
								{
									currentPlayer->addRoad(pathCoordinate);
									gameStateRef->setIsBuyRoadButtonPressed(false);
									// round >=2
									if(turnCounter > gameStateRef->getNumberOfPlayers()){
										gameStateRef->setIsBuyRoadButtonEnabled(true);
										gameStateRef->setIsBuySettlementButtonEnabled(true);
										gameStateRef->setIsCityUpgradeButtonEnabled(true);
										gameStateRef->setIsBuyDevelopmentCardButtonEnabled(true);
										gameStateRef->setIsPlayerTradeButtonEnabled(true);
										gameStateRef->setIsBankTradeButtonEnabled(true);
										gameStateRef->setIsEndTurnButtonEnabled(true);
									}
									// first round
									else{
										if(currentPlayer->getNmbOfSettlementsPlaced()<2){
											if(currentPlayer->getNmbOfRoadsPlaced()<2)
												gameStateRef->setIsBuyRoadButtonEnabled(true);
											else
												gameStateRef->setIsBuyRoadButtonEnabled(false);
											gameStateRef->setIsBuySettlementButtonEnabled(true);
											gameStateRef->setIsEndTurnButtonEnabled(false);
										}
										else{
											if(currentPlayer->getNmbOfRoadsPlaced()<2)
												gameStateRef->setIsBuyRoadButtonEnabled(true);
											else
												gameStateRef->setIsBuyRoadButtonEnabled(false);
											gameStateRef->setIsBuySettlementButtonEnabled(false);
											gameStateRef->setIsEndTurnButtonEnabled(true);
										}
										gameStateRef->setIsCityUpgradeButtonEnabled(false);
										gameStateRef->setIsBuyDevelopmentCardButtonEnabled(false);
										gameStateRef->setIsPlayerTradeButtonEnabled(false);
										gameStateRef->setIsBankTradeButtonEnabled(false);
									}
								}
							}
						}
					}
				}
			}
		}

		
		/*		CLAUDIU'S CODE START			*/
		if(clickedStartTrade){			//only do this if trade was initiated
			int stringCharWidth = 7;			//default character length of [sheep] or [wood ], etc
			int leftCharPosition;
			int topCharPosition;
			float leftStartTrade;
			float rightStartTrade;
			float topStartTrade;
			float bottomStartTrade;
			int leftCharPositionArray[3] = {0,17,35};
			int showFrom = 4;
			int showTo   = 9;
			//madeTradeOffer = false;			//[NEW]

			for (int i=showFrom; i<showTo; i++){				//modify HERE if data is pushed down the screen
				topCharPosition = i;
				for (int j=0; j<3; j++){
					//std::cout << "SHOWED: i = " << i << " j value is " << leftCharPositionArray[j] << std::endl;
					leftCharPosition = leftCharPositionArray[j];

					leftStartTrade = textLeft+(leftCharPosition*textWidth);
					rightStartTrade = textLeft+((leftCharPosition + stringCharWidth)*textWidth);
					topStartTrade = textTop + textHeight*topCharPosition;
					bottomStartTrade = textTop + textHeight*(topCharPosition+1);

					//a resource location has been clicked
					if (clickedStartTrade && leftStartTrade < clientX && rightStartTrade > clientX && topStartTrade < clientY && bottomStartTrade > clientY)
					{
						if (topCharPosition == showFrom && leftCharPosition == 0){
							std::cout << "SHOWED: Want to TradeIN wood" << std::endl;
							if(TradeFor.getWood() > 0){			//decrement demand 
								TradeFor = TradeFor - catan::resourceWood;
							}
							else{								//Increase offer
								TradeIn = TradeIn + (catan::resourceWood*woodMultiplier);
							}
						}
						else if (topCharPosition == showFrom && leftCharPosition == 17){
							std::cout << "SHOWED: Want to TradeFor wood" << std::endl;
							if(TradeIn.getWood() > 0){			//decrement OFFER
								TradeIn = TradeIn - (catan::resourceWood*woodMultiplier); 
							}
							else{								//INCREASE DEMAND
								TradeFor = TradeFor + catan::resourceWood; // * multiplier
							}
						}
						else if (topCharPosition == showFrom+1 && leftCharPosition == 0){
							std::cout << "SHOWED: Want to TradeIN sheep" << std::endl;
							if(TradeFor.getSheep() > 0){			//decrement demand 
								TradeFor = TradeFor - catan::resourceSheep;
							}
							else{								//Increase offer
								TradeIn = TradeIn + (catan::resourceSheep*sheepMultiplier);
							}
						}
						else if (topCharPosition == showFrom+1 && leftCharPosition == 17){
							std::cout << "SHOWED: Want to TradeFor sheep" << std::endl;
							if(TradeIn.getSheep() > 0){			//decrement OFFER
								TradeIn = TradeIn - (catan::resourceSheep*sheepMultiplier);
							}
							else{								//INCREASE DEMAND
								TradeFor = TradeFor + catan::resourceSheep;
							}
						}
						else if (topCharPosition == showFrom+2 && leftCharPosition == 0){
							std::cout << "SHOWED: Want to TradeIN wheat" << std::endl;
							if(TradeFor.getWheat() > 0){			//decrement demand 
								TradeFor = TradeFor - catan::resourceWheat;
							}
							else{								//Increase offer
								TradeIn = TradeIn + (catan::resourceWheat*wheatMultiplier);
							}
						}
						else if (topCharPosition == showFrom+2 && leftCharPosition == 17){
							std::cout << "SHOWED: Want to TradeFor wheat" << std::endl;
							if(TradeIn.getWheat() > 0){			//decrement OFFER
								TradeIn = TradeIn - (catan::resourceWheat*wheatMultiplier);
							}
							else{								//INCREASE DEMAND
								TradeFor = TradeFor + catan::resourceWheat;
							}
						}
						else if (topCharPosition == showFrom+3 && leftCharPosition == 0){
							std::cout << "SHOWED: Want to TradeIN brick" << std::endl;
							if(TradeFor.getBrick() > 0){			//decrement demand 
								TradeFor = TradeFor - catan::resourceBrick;
							}
							else{								//Increase offer
								TradeIn = TradeIn + (catan::resourceBrick*brickMultiplier);
							}
						}
						else if (topCharPosition == showFrom+3 && leftCharPosition == 17){
							std::cout << "SHOWED: Want to TradeFor brick" << std::endl;
							if(TradeIn.getBrick() > 0){			//decrement OFFER
								TradeIn = TradeIn - (catan::resourceBrick*brickMultiplier);
							}
							else{								//INCREASE DEMAND
								TradeFor = TradeFor + catan::resourceBrick;
							}
						}
						else if (topCharPosition == showFrom+4 && leftCharPosition == 0){
							std::cout << "SHOWED: Want to TradeIN ore" << std::endl;
							if(TradeFor.getOre() > 0){			//decrement demand 
								TradeFor = TradeFor - catan::resourceOre;
							}
							else{								//Increase offer
								TradeIn = TradeIn + (catan::resourceOre*oreMultiplier);
							}
						}
						else if (topCharPosition == showFrom+4 && leftCharPosition == 17){
							std::cout << "SHOWED: Want to TradeFor ore" << std::endl;
							if(TradeIn.getOre() > 0){			//decrement OFFER
								TradeIn = TradeIn - (catan::resourceOre*oreMultiplier);
							}
							else{								//INCREASE DEMAND
								TradeFor = TradeFor + catan::resourceOre;
							}
						}
						else if (topCharPosition == showFrom+2 && leftCharPosition == 35){			//OFFER menu was clicked
							//check if (TradeIn != 0 && TradeFor != 0 && Player.Resources.containsAtLeast(TradeIn))
							//check that the P1 has the resources it wants to offer.
							std::cout << "SHOWED: Want to start trade [OFFER]" << std::endl;
							//if (TradeIn
							madeTradeOffer = true;
							playerTradeCompleted = false;
							nextPlayerIndex = gameStateRef->getPlayerIndex()+1;
							PlayersAcceptedTrade.clear();
							//TradeIn = ResourceSet(0,0,0,0,0);				//reset resource
							//TradeFor = ResourceSet(0,0,0,0,0);				//reset resource
						}
					}
				}
			}

			stringCharWidth = 5;
			topCharPosition = 11;
			leftCharPosition = 41;				//position for [YES]
			//leftCharPosition = 49;				//position for [NO ]		//if [NO ] was pressed do nothing
			//BUGGY MINOR SINCE it will show the NO exacly where the YES should have been if it doesn't have the resources
			leftStartTrade = textLeft+(leftCharPosition*textWidth);
			rightStartTrade = textLeft+((leftCharPosition + stringCharWidth)*textWidth);
			topStartTrade = textTop + textHeight*topCharPosition;
			bottomStartTrade = textTop + textHeight*(topCharPosition+1);

			//detecting the click on [YES] accepting the trade by the player
			if (clickedTradePlayers && madeTradeOffer && leftStartTrade < clientX && 
				rightStartTrade > clientX && topStartTrade < clientY && bottomStartTrade > clientY){
					std::cout << "SHOWED: YOU ACCEPTED THE OFFER" << std::endl;
					PlayersAcceptedTrade.push_back(gameStateRef->getPlayers().at(nextPlayerIndex));
					++nextPlayerIndex;

					//put current player in accepted vector<Player> PlayersAcceptedTrade; and goto next player
			}

			leftCharPosition = 49;
			leftStartTrade = textLeft+(leftCharPosition*textWidth);
			rightStartTrade = textLeft+((leftCharPosition + stringCharWidth)*textWidth);
			topStartTrade = textTop + textHeight*topCharPosition;
			bottomStartTrade = textTop + textHeight*(topCharPosition+1);

			//detecting the click on [NO ] accepting the trade by the player
			if (clickedTradePlayers && madeTradeOffer && leftStartTrade < clientX && 
				rightStartTrade > clientX && topStartTrade < clientY && bottomStartTrade > clientY){
					std::cout << "SHOWED: YOU DECLINED THE OFFER" << std::endl;
					++nextPlayerIndex;

					//DO NOT put current player in accepted vector<Player> PlayersAcceptedTrade; and goto next player
			}

			Player* currentPlayer;
			ResourceSet playerResources;
			Player* nextPlayer;

			for (int k=0; k<static_cast<int>(PlayersAcceptedTrade.size()); k++){
				if (k+1 == 1){
					topCharPosition = 10;
				}
				else if(k+1 == 2){
					topCharPosition = 11;
				}
				else if(k+1 == 3){			//want to trade with 3rd person shown
					topCharPosition = 12;
				}

				stringCharWidth = 7;
				leftCharPosition = 0;
				leftStartTrade = textLeft+(leftCharPosition*textWidth);
				rightStartTrade = textLeft+((leftCharPosition + stringCharWidth)*textWidth);
				topStartTrade = textTop + textHeight*topCharPosition;
				bottomStartTrade = textTop + textHeight*(topCharPosition+1);

				currentPlayer = gameStateRef->getPlayers().at(gameStateRef->getPlayerIndex());
				playerResources = currentPlayer->getResources();

				if (acceptPlayerTrade && clickedTradePlayers && madeTradeOffer && leftStartTrade < clientX && 
				rightStartTrade > clientX && topStartTrade < clientY && bottomStartTrade > clientY){
					
					int nextPlayerIndex = gameStateRef->getPlayerIndex()+1+k;				//using k as calculation
					int modPlayer = nextPlayerIndex % gameStateRef->getNumberOfPlayers();
					nextPlayerIndex = modPlayer;
					//PlayersAcceptedTrade.at(k);

					playerTraderName = PlayersAcceptedTrade.at(k)->getName();

					std::cout << "ACCEPTED TO TRADE WITH PLAYER " << playerTraderName << std::endl;

					//nextPlayer = gameStateRef->getPlayers().at(modPlayer);		//gets the next player
					nextPlayer = PlayersAcceptedTrade.at(k);


					//detect the position to which player it accepted. 
					//if first [TRADE] then next player, if 2nd then next next player, etc, use for loop

					currentPlayer->setResources(currentPlayer->getResources() - TradeIn);
					currentPlayer->setResources(currentPlayer->getResources() + TradeFor);
					nextPlayer->setResources(nextPlayer->getResources() - TradeFor);
					nextPlayer->setResources(nextPlayer->getResources() + TradeIn);

					PlayersAcceptedTrade.clear();
					acceptPlayerTrade = false;

					//playerTraderIndex = nextPlayerIndex;
					
					playerTradeCompleted = true;			//the end of the player trade
					TradeIn = ResourceSet(0,0,0,0,0);
					TradeFor = ResourceSet(0,0,0,0,0);
				}
			}
		}
	}
}


bool GLScene::isOkToPlaceRoad(PathCoordinate theCoordinate){
	return false;
}

bool GLScene::isOkToPlaceSettlement(SiteCoordinate theCoordinate){
	return false;
}

} // end of catan namespace
